{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Direction</th>\n",
       "      <th>District</th>\n",
       "      <th>Elevator</th>\n",
       "      <th>Floor</th>\n",
       "      <th>Garden</th>\n",
       "      <th>Id</th>\n",
       "      <th>Layout</th>\n",
       "      <th>Price</th>\n",
       "      <th>Region</th>\n",
       "      <th>Renovation</th>\n",
       "      <th>Size</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>东西</td>\n",
       "      <td>灯市口</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "      <td>锡拉胡同21号院</td>\n",
       "      <td>101102647043</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>780.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>75.0</td>\n",
       "      <td>1988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>南北</td>\n",
       "      <td>东单</td>\n",
       "      <td>无电梯</td>\n",
       "      <td>6</td>\n",
       "      <td>东华门大街</td>\n",
       "      <td>101102650978</td>\n",
       "      <td>2室1厅</td>\n",
       "      <td>705.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>60.0</td>\n",
       "      <td>1988</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>南西</td>\n",
       "      <td>崇文门</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>16</td>\n",
       "      <td>新世界中心</td>\n",
       "      <td>101102672743</td>\n",
       "      <td>3室1厅</td>\n",
       "      <td>1400.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>其他</td>\n",
       "      <td>210.0</td>\n",
       "      <td>1996</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>南</td>\n",
       "      <td>崇文门</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7</td>\n",
       "      <td>兴隆都市馨园</td>\n",
       "      <td>101102577410</td>\n",
       "      <td>1室1厅</td>\n",
       "      <td>420.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>39.0</td>\n",
       "      <td>2004</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>南</td>\n",
       "      <td>陶然亭</td>\n",
       "      <td>有电梯</td>\n",
       "      <td>19</td>\n",
       "      <td>中海紫御公馆</td>\n",
       "      <td>101102574696</td>\n",
       "      <td>2室2厅</td>\n",
       "      <td>998.0</td>\n",
       "      <td>东城</td>\n",
       "      <td>精装</td>\n",
       "      <td>90.0</td>\n",
       "      <td>2010</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Direction District Elevator  Floor    Garden            Id Layout   Price  \\\n",
       "0        东西      灯市口      NaN      6  锡拉胡同21号院  101102647043   3室1厅   780.0   \n",
       "1        南北       东单      无电梯      6     东华门大街  101102650978   2室1厅   705.0   \n",
       "2        南西      崇文门      有电梯     16     新世界中心  101102672743   3室1厅  1400.0   \n",
       "3         南      崇文门      NaN      7    兴隆都市馨园  101102577410   1室1厅   420.0   \n",
       "4         南      陶然亭      有电梯     19    中海紫御公馆  101102574696   2室2厅   998.0   \n",
       "\n",
       "  Region Renovation   Size  Year  \n",
       "0     东城         精装   75.0  1988  \n",
       "1     东城         精装   60.0  1988  \n",
       "2     东城         其他  210.0  1996  \n",
       "3     东城         精装   39.0  2004  \n",
       "4     东城         精装   90.0  2010  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "file = pd.read_csv('lianjia.csv')\n",
    "file.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "23677"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(file)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "先进行空值的统计分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 0, 8237, 0, 0, 0, 0, 0, 0, 0, 0, 0]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "nalist_cnt = []\n",
    "for i in file.columns:\n",
    "    nalist_cnt.append(file[i].isnull().sum())\n",
    "nalist_cnt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可见，只有电梯情况这一列有较大缺失情况，其他的没有缺失。对电梯缺失的情况用“未知”填补"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "file['Elevator'].fillna(value='未知', inplace = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 再次进行统计分析\n",
    "nalist_cnt = []\n",
    "for i in file.columns:\n",
    "    nalist_cnt.append(file[i].isnull().sum())\n",
    "nalist_cnt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "连续性变量的统计分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "con_index = ['Floor', 'Price', 'Size', 'Year']\n",
    "sta_data = pd.DataFrame(columns = ['指标名称', '最小值', '第一分位数', '中位数', '均值', '第三分位数', '最大值'])\n",
    "row_cnt = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>指标名称</th>\n",
       "      <th>最小值</th>\n",
       "      <th>第一分位数</th>\n",
       "      <th>中位数</th>\n",
       "      <th>均值</th>\n",
       "      <th>第三分位数</th>\n",
       "      <th>最大值</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Floor</td>\n",
       "      <td>1.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>11.0</td>\n",
       "      <td>12.765</td>\n",
       "      <td>18.0</td>\n",
       "      <td>57.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Price</td>\n",
       "      <td>60.0</td>\n",
       "      <td>365.0</td>\n",
       "      <td>499.0</td>\n",
       "      <td>610.668</td>\n",
       "      <td>717.0</td>\n",
       "      <td>6000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Size</td>\n",
       "      <td>2.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>88.0</td>\n",
       "      <td>99.149</td>\n",
       "      <td>118.0</td>\n",
       "      <td>1019.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Year</td>\n",
       "      <td>1950.0</td>\n",
       "      <td>1997.0</td>\n",
       "      <td>2003.0</td>\n",
       "      <td>2001.327</td>\n",
       "      <td>2007.0</td>\n",
       "      <td>2017.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    指标名称     最小值   第一分位数     中位数        均值   第三分位数     最大值\n",
       "1  Floor     1.0     6.0    11.0    12.765    18.0    57.0\n",
       "2  Price    60.0   365.0   499.0   610.668   717.0  6000.0\n",
       "3   Size     2.0    66.0    88.0    99.149   118.0  1019.0\n",
       "4   Year  1950.0  1997.0  2003.0  2001.327  2007.0  2017.0"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "for i in range(0, len(con_index)):\n",
    "    alist = []\n",
    "    alist.append(con_index[i])\n",
    "    alist.append(min(file[con_index[i]].astype(float)))\n",
    "    alist.append(file[con_index[i]].astype(float).quantile(q=0.25))\n",
    "    alist.append(file[con_index[i]].astype(float).quantile(q=0.5))\n",
    "    alist.append(round(sum(file[con_index[i]].astype(float)) / len(file) , 3))\n",
    "    alist.append(file[con_index[i]].astype(float).quantile(q=0.75))\n",
    "    alist.append(max(file[con_index[i]].astype(float)))\n",
    "    sta_data.loc[row_cnt] = alist\n",
    "    row_cnt += 1\n",
    "sta_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Floor</th>\n",
       "      <th>Price</th>\n",
       "      <th>Size</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>23677.000000</td>\n",
       "      <td>23677.000000</td>\n",
       "      <td>23677.000000</td>\n",
       "      <td>23677.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>12.765088</td>\n",
       "      <td>610.668319</td>\n",
       "      <td>99.149301</td>\n",
       "      <td>2001.326519</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>7.643932</td>\n",
       "      <td>411.452107</td>\n",
       "      <td>50.988838</td>\n",
       "      <td>9.001996</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>60.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>1950.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>6.000000</td>\n",
       "      <td>365.000000</td>\n",
       "      <td>66.000000</td>\n",
       "      <td>1997.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>11.000000</td>\n",
       "      <td>499.000000</td>\n",
       "      <td>88.000000</td>\n",
       "      <td>2003.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>18.000000</td>\n",
       "      <td>717.000000</td>\n",
       "      <td>118.000000</td>\n",
       "      <td>2007.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>57.000000</td>\n",
       "      <td>6000.000000</td>\n",
       "      <td>1019.000000</td>\n",
       "      <td>2017.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Floor         Price          Size          Year\n",
       "count  23677.000000  23677.000000  23677.000000  23677.000000\n",
       "mean      12.765088    610.668319     99.149301   2001.326519\n",
       "std        7.643932    411.452107     50.988838      9.001996\n",
       "min        1.000000     60.000000      2.000000   1950.000000\n",
       "25%        6.000000    365.000000     66.000000   1997.000000\n",
       "50%       11.000000    499.000000     88.000000   2003.000000\n",
       "75%       18.000000    717.000000    118.000000   2007.000000\n",
       "max       57.000000   6000.000000   1019.000000   2017.000000"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 也可以直接调用函数进行分析\n",
    "file_a = file[con_index]\n",
    "file_a.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可以看到，指标名称为size的最小值存在数据异常问题，size为房间大小，最小值为2不符合实际情况"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Direction</th>\n",
       "      <th>District</th>\n",
       "      <th>Elevator</th>\n",
       "      <th>Floor</th>\n",
       "      <th>Garden</th>\n",
       "      <th>Id</th>\n",
       "      <th>Layout</th>\n",
       "      <th>Price</th>\n",
       "      <th>Region</th>\n",
       "      <th>Renovation</th>\n",
       "      <th>Size</th>\n",
       "      <th>Year</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>7533</th>\n",
       "      <td>107.93平米</td>\n",
       "      <td>回龙观</td>\n",
       "      <td>简装</td>\n",
       "      <td>4</td>\n",
       "      <td>龙城花园N区</td>\n",
       "      <td>101101993058</td>\n",
       "      <td>叠拼别墅</td>\n",
       "      <td>620.0</td>\n",
       "      <td>昌平</td>\n",
       "      <td>南北</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1997</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     Direction District Elevator  Floor  Garden            Id Layout  Price  \\\n",
       "7533  107.93平米      回龙观       简装      4  龙城花园N区  101101993058   叠拼别墅  620.0   \n",
       "\n",
       "     Region Renovation  Size  Year  \n",
       "7533     昌平         南北   2.0  1997  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 调出异常值数据情况，进行分析\n",
    "tmp_file = file[(file['Size'] == 2.0)]\n",
    "tmp_file"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "此数据异常，应剔除，另外，对size的最小前30条进行统计分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2.0,\n",
       " 4.0,\n",
       " 4.0,\n",
       " 4.0,\n",
       " 4.0,\n",
       " 4.0,\n",
       " 4.0,\n",
       " 4.0,\n",
       " 4.0,\n",
       " 4.0,\n",
       " 4.0,\n",
       " 5.0,\n",
       " 5.0,\n",
       " 5.0,\n",
       " 5.0,\n",
       " 5.0,\n",
       " 5.0,\n",
       " 5.0,\n",
       " 6.0,\n",
       " 8.0,\n",
       " 15.0,\n",
       " 16.0,\n",
       " 16.0,\n",
       " 19.0,\n",
       " 19.0,\n",
       " 20.0,\n",
       " 20.0,\n",
       " 20.0,\n",
       " 21.0,\n",
       " 22.0]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "size_list = list(file['Size'])\n",
    "sorted(size_list)[:30]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "异常值较多，取数分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['北', '沙河', '无电梯', 6, '善缘嘉园', 101102619706, '1室1厅', 138.0, '昌平', '简装', 22.0, 2006]\n",
      "['西', '沙河', '有电梯', 17, '北街家园七区', 101102651491, '1室1厅', 180.0, '昌平', '简装', 19.0, 2010]\n",
      "['240.97平米', '长阳', '毛坯', 5, '世茂维拉', 101102253577, '叠拼别墅', 1080.0, '房山', '南北', 5.0, 2015]\n",
      "['242.78平米', '长阳', '毛坯', 5, '世茂维拉', 101102217569, '叠拼别墅', 1100.0, '房山', '南北', 5.0, 2015]\n",
      "['242.96平米', '长阳', '精装', 5, '世茂维拉', 101101911559, '叠拼别墅', 980.0, '房山', '南北', 5.0, 2015]\n",
      "['295.88平米', '顺义其它', '精装', 4, '龙湖好望山', 101102431983, '叠拼别墅', 1000.0, '顺义', '南北', 4.0, 2014]\n",
      "['295.01平米', '顺义其它', '精装', 4, '鹭峯国际', 101102300614, '叠拼别墅', 1450.0, '顺义', '南北', 5.0, 2014]\n",
      "['292.31平米', '顺义其它', '毛坯', 3, '龙湖好望山', 101102013095, '叠拼别墅', 860.0, '顺义', '南北', 4.0, 2014]\n",
      "['294.42平米', '顺义其它', '精装', 5, '龙湖好望山', 101101141445, '叠拼别墅', 980.0, '顺义', '南北', 6.0, 2013]\n",
      "['427.5平米', '西红门', '精装', 3, '鸿坤林语墅', 101102023530, '叠拼别墅', 3150.0, '大兴', '南北', 4.0, 2015]\n",
      "['361.8平米', '西红门', '精装', 4, '鸿坤林语墅', 101102460862, '叠拼别墅', 2380.0, '大兴', '南北', 4.0, 2015]\n",
      "['386.83平米', '西红门', '精装', 3, '鸿坤林语墅', 101102411099, '叠拼别墅', 2700.0, '大兴', '南北', 5.0, 2015]\n",
      "['107.93平米', '回龙观', '简装', 4, '龙城花园N区', 101101993058, '叠拼别墅', 620.0, '昌平', '南北', 2.0, 1997]\n",
      "['195.32平米', '通州其它', '毛坯', 6, '旭辉御锦', 101102638903, '叠拼别墅', 780.0, '通州', '南北', 5.0, 2014]\n",
      "['259.87平米', '通州其它', '精装', 6, '旭辉御锦', 101101801342, '叠拼别墅', 1120.0, '通州', '南北', 4.0, 2014]\n",
      "['259.76平米', '通州其它', '毛坯', 6, '旭辉御锦', 101102046256, '叠拼别墅', 1050.0, '通州', '南北', 4.0, 2014]\n",
      "['260.07平米', '通州其它', '精装', 6, '旭辉御锦', 101102490792, '叠拼别墅', 1050.0, '通州', '南北', 4.0, 2014]\n",
      "['264.6平米', '通州其它', '毛坯', 6, '旭辉御锦', 101102440907, '叠拼别墅', 1100.0, '通州', '南北', 4.0, 2014]\n",
      "['335.51平米', '丽泽', '毛坯', 6, '西宸原著', 101102306757, '叠拼别墅', 4000.0, '丰台', '南北', 4.0, 2016]\n",
      "['266.61平米', '西山', '精装', 3, '中间建筑一区', 101101869900, '叠拼别墅', 1350.0, '海淀', '南北', 8.0, 2007]\n",
      "['203.73平米', '西山', '简装', 4, '西山美墅馆F区', 101102520575, '叠拼别墅', 2200.0, '海淀', '南北', 4.0, 2004]\n",
      "['523.4平米', '大望路', '精装', 5, '首府官邸', 101102432328, '叠拼别墅', 4500.0, '朝阳', '南北', 5.0, 2007]\n",
      "['北', '广安门', '有电梯', 20, '荣丰2008', 101102739396, '1室0厅', 295.0, '西城', '其他', 22.0, 2004]\n",
      "['南', '六铺炕', '未知', 1, '西绦南巷', 101102645058, '1室1厅', 213.0, '西城', '简装', 15.0, 2009]\n",
      "['北', '广安门', '有电梯', 20, '荣丰2008', 101102739396, '1室0厅', 295.0, '西城', '其他', 22.0, 2004]\n",
      "['东', '广安门', '未知', 26, '荣丰2008', 101102716720, '1室0厅', 280.0, '西城', '简装', 19.0, 2006]\n",
      "['北', '广安门', '有电梯', 20, '荣丰2008', 101102675988, '1室0厅', 293.0, '西城', '其他', 21.0, 2004]\n",
      "['南', '广安门', '未知', 26, '荣丰2008', 101102356432, '1室0厅', 305.0, '西城', '简装', 22.0, 2006]\n",
      "['西', '东四', '有电梯', 3, '华人一品阁', 101102696180, '1房间1卫', 98.0, '东城', '精装', 20.0, 2007]\n",
      "['东', '东四', '未知', 3, '华人一品阁', 101102573605, '1房间1卫', 105.0, '东城', '毛坯', 20.0, 2007]\n",
      "['南', '东四', '有电梯', 3, '华人一品阁', 101101915230, '1房间1卫', 90.0, '东城', '简装', 16.0, 2006]\n",
      "['南', '东四', '有电梯', 3, '华人一品阁', 101101915213, '1房间1卫', 90.0, '东城', '简装', 16.0, 2006]\n",
      "['东', '东四', '有电梯', 3, '华人一品阁', 101101996706, '1房间1卫', 98.0, '东城', '其他', 20.0, 2007]\n"
     ]
    }
   ],
   "source": [
    "tmplist = sorted(size_list)[:30]\n",
    "for i in range(0, len(file)):\n",
    "    if file['Size'].iloc[i] in tmplist:\n",
    "        print(list(file.iloc[i]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可以看见，这部分的数据为错填数据，Direction错填为面积，该部分信息需剔除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_data = pd.DataFrame(columns = file.columns)\n",
    "row_cnt = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-14-40b970f4a0af>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfile\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfile\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'Direction'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0miloc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m<=\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m:\u001b[0m     \u001b[1;31m# 大于2的剔除\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m         \u001b[0mdf_data\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mrow_cnt\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfile\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0miloc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      4\u001b[0m         \u001b[0mrow_cnt\u001b[0m \u001b[1;33m+=\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[0mdf_data\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mhead\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\conda\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   1476\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1477\u001b[0m             \u001b[0mmaybe_callable\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcom\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_apply_if_callable\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mobj\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1478\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_getitem_axis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmaybe_callable\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1479\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1480\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_is_scalar_access\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\conda\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m_getitem_axis\u001b[1;34m(self, key, axis)\u001b[0m\n\u001b[0;32m   2102\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_validate_integer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2103\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2104\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   2105\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2106\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_convert_to_indexer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mobj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mis_setter\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\conda\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m_get_loc\u001b[1;34m(self, key, axis)\u001b[0m\n\u001b[0;32m    143\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0maxis\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    144\u001b[0m             \u001b[0maxis\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 145\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mobj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_ixs\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    146\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    147\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_slice\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mobj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkind\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\conda\\lib\\site-packages\\pandas\\core\\frame.py\u001b[0m in \u001b[0;36m_ixs\u001b[1;34m(self, i, axis)\u001b[0m\n\u001b[0;32m   2624\u001b[0m                                                       \u001b[0mindex\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2625\u001b[0m                                                       \u001b[0mname\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2626\u001b[1;33m                                                       dtype=new_values.dtype)\n\u001b[0m\u001b[0;32m   2627\u001b[0m                 \u001b[0mresult\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_set_is_copy\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcopy\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcopy\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2628\u001b[0m                 \u001b[1;32mreturn\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\conda\\lib\\site-packages\\pandas\\core\\series.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, data, index, dtype, name, copy, fastpath)\u001b[0m\n\u001b[0;32m    279\u001b[0m         \u001b[0mgeneric\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mNDFrame\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__init__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfastpath\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    280\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 281\u001b[1;33m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mname\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    282\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_set_axis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mindex\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfastpath\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    283\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\conda\\lib\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36m__setattr__\u001b[1;34m(self, name, value)\u001b[0m\n\u001b[0;32m   4385\u001b[0m         \u001b[1;31m# the same attribute.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4386\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 4387\u001b[1;33m         \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   4388\u001b[0m             \u001b[0mobject\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4389\u001b[0m             \u001b[1;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__setattr__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "for i in range(0, len(file)):\n",
    "    if len(file['Direction'].iloc[i]) <= 2:     # 大于2的剔除\n",
    "        df_data.loc[row_cnt] = file.iloc[i]\n",
    "        row_cnt += 1\n",
    "df_data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_data.to_csv('清洗后的数据.csv', encoding = 'gb18030', index = False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
